package org.jsola.hr.constant;

import org.jsola.core.validator.IConst;
import org.jsola.json.JsonKit;

import java.util.HashMap;
import java.util.Map;

/**
 * 人事变动类型枚举
 *
 * @author ds
 */
public enum PersonalEventEnum implements IConst {

    /**
     * 添加至系统
     */
    ADD("1","添加至系统"),
    /**
     * 办理入职
     */
    ENTRY_PROCEDURE("2","办理入职"),
    /**
     * 正式入职
     */
    ENTRY("3","正式入职"),
    /**
     * 员工转正
     */
    REGULAR_WORKER("4","员工转正"),
    /**
     * 办理离职
     */
    EXIT_PROCEDURE("5","办理离职"),
    /**
     * 正式离职
     */
    EXIT("6","正式离职"),
    /**
     * 办理调岗
     */
    TRANSFER_PROCEDURE("7","办理调岗"),
    /**
     * 正式调岗
     */
    TRANSFER("8","正式调岗"),
    /**
     * 审批
     */
    APPROVAL("9","审批"),
    /**
     * 撤销离职
     */
    REVOKE_LEAVE("10","撤销离职"),
    /**
     * 撤销调岗
     */
    REVOKE_TRANSFER("11","撤销调岗"),
    /**
     * 手动添加
     */
    ADD_MANUALLY("12","手动添加"),
    /**
     * 实名认证已认证
     */
    VERIFIED("13","实名认证已认证"),
    /**
     * 个人信息已完善
     */
    DETAILS_INFO("14","个人信息已完善"),
    /**
     * 员工签署完毕
     */
    CONTRACT_EMP("15","员工签署完毕"),
    /**
     * 增员
     */
    INCREASE("16","增员"),
    /**
     * 增员确认
     */
    INCREASE_CONFIRM("17","增员确认"),
    /**
     * 减员
     */
    DECREASE("18","减员"),
    /**
     * 减员确认
     */
    DECREASE_CONFIRM("19","减员确认"),
    /**
     * 补缴
     */
    FILL_PAYMENT("20","补缴"),
    /**
     * 补收
     */
    FILL_GATHER("21","补收"),
    /**
     * 用工单位签署
     */
    CONTRACT_COMPANY("22","用工单位签署"),
    /**
     * 员工定薪
     */
    FIX_SALARY("23","员工定薪"),
    /**
     * 员工调薪
     */
    CHANGE_SALARY("24","员工调薪"),
    /**
     * 办理工价规则
     */
    SALARY_RULE("25","办理工价规则"),
    /**
     * 办理劳务费规则
     */
    SERVICE_RULE("26","办理劳务费规则");

    private final String value;
    private final String desc;
    /**
     * 枚举值罗列，给swagger接口文档展示用
     */
    public static final String VALUES_STR = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26";

     /**
     * 缓存所有value
     */
    private static final Map<String, PersonalEventEnum> LOOKUP = new HashMap<>();

    static {
        for (PersonalEventEnum e : PersonalEventEnum.values()) {
            LOOKUP.put(e.value, e);
        }
    }


    PersonalEventEnum(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    /**
     * 根据value查找PersonalEventEnum
     * @param value value
     * @return PersonalEventEnum
     */
    public static PersonalEventEnum find(String value) {
        return LOOKUP.get(value);
    }

    /**
     * 根据desc查找PersonalEventEnum
     * @param desc desc
     * @return PersonalEventEnum
     */
    public static PersonalEventEnum findByDesc(String desc){
        for (PersonalEventEnum e : PersonalEventEnum.values()) {
            if(e.getDesc().equals(desc)){
                return e;
            }
        }
        return null;
    }

    /**
     * 所有枚举转json
     * @return json
     */
    public static String getAllToJson() {
        Map<String,Object> map = new HashMap<>();
        for (PersonalEventEnum e : PersonalEventEnum.values()) {
            map.put("value", e.value);
            map.put("desc", e.desc);
        }
        return JsonKit.toJSONString(map);
    }

    @Override
    public boolean check(Object obj) {
        String value = (String) obj;
        return find(value) != null;
    }

    public String getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }
}
